/*
 * $Id: UpdateEmailSettingAction.java 3 2011-12-26 07:48:43Z forwardly@hotmail.com $
 * 
 * Copyright (c) 2001-2008 Accentrix Company Limited. All Rights Reserved.
 * 
 * Accentrix Company Limited. ("Accentrix") retains copyright on all text, source
 * and binary code contained in this software and documentation. Accentrix grants
 * Licensee a limited license to use this software, provided that this copyright
 * notice and license appear on all copies of the software. The software source
 * code is provided for reference purposes only and may not be copied, modified 
 * or distributed.
 * 
 * THIS SOFTWARE AND DOCUMENTATION ARE PROVIDED "AS IS," WITHOUT ANY WARRANTY OF
 * ANY KIND UNLESS A SEPARATE WARRANTIES IS PURCHASED FROM ACCENTRIX AND REMAINS
 * VALID.  ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES,
 * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
 * PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. ACCENTRIX SHALL NOT BE LIABLE
 * FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING OR MODIFYING THE
 * SOFTWARE OR ITS DERIVATIVES.
 * 
 * IN NO EVENT WILL ACCENTRIX BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR
 * FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES,
 * HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF THE
 * USE OF OR INABILITY TO USE SOFTWARE, EVEN IF ACCENTRIX HAS BEEN ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGES.
 */
package com.lightsaber.trade.as.web.email;

import java.util.List;
import java.util.Map;

import org.apache.struts2.convention.annotation.Namespace;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;

import com.lightsaber.trade.as.entity.email.EmailSetting;
import com.lightsaber.trade.as.service.email.EmailSettingManager;
import com.lightsaber.trade.core.web.BaseAction;

@Namespace("/email")
public class UpdateEmailSettingAction extends BaseAction {

    private static final long serialVersionUID = -6859614862278140929L;

    @Autowired
    private EmailSettingManager emailSettingManager;

    @Value(value = "#{appProperties['app.code']}")
    private String appCode = "HPP";

    private EmailSetting emailSetting = new EmailSetting();

    // private List<Role> roleList;
    private Map<String, String> roleMap;
    private List<String> selectRoleCodes;

    @Override
    public String execute() throws Exception {
        emailSettingManager.saveBySelectRoles(emailSetting.getEmailNotificationType(),
                selectRoleCodes);

        addActionMessage(getText(PROCESSED_SUCCESS));

        return SUCCESS;
    }

    @Override
    public String input() throws Exception {
        // roleList = roleService.findByAppCode(appCode);
        // roleMap = new HashMap<String, String>();
        // List<EmailSetting> emailSettingList = emailSettingManager
        // .findByEmailNotificationType(emailSetting.getEmailNotificationType());
        // for (EmailSetting emailSetting : emailSettingList) {
        // roleMap.put(emailSetting.getRoleCode(), emailSetting.getRoleCode());
        // }
        return INPUT;
    }

    public EmailSetting getEmailSetting() {
        return emailSetting;
    }

    public Map<String, String> getRoleMap() {
        return roleMap;
    }

    public void setEmailSettingManager(final EmailSettingManager emailSettingManager) {
        this.emailSettingManager = emailSettingManager;
    }

    public void setAppCode(final String appCode) {
        this.appCode = appCode;
    }

    public List<String> getSelectRoleCodes() {
        return selectRoleCodes;
    }

    public void setSelectRoleCodes(final List<String> selectRoleCodes) {
        this.selectRoleCodes = selectRoleCodes;
    }
}
